<?php

function logIt($msg) {
    error_log($msg);
}

//Include the base interfaces which plugins can implement
include_once('interfaces.php');
//Include the class for the base structure
include_once('site.class.php');

//Enable autoloading of plugins
function __autoload($classname)
{
    error_log("Attempting to autoload $classname");
    include_once('plugins/'.$classname.'.class.php');    
}

$sources = array();
$site = new Site();

include_once("conf.php");

if (isset($_GET['source']) && isset($sources[intval($_GET['source'])])) {
    $source_id = intval($_GET['source']);
    $photo_source =& $sources[$source_id];
} else {
    $source_id = 0;
    $photo_source = array_pop($sources);
}

if (!($photo_source instanceof PhotoSource_I)) {
    die(sprintf("%d photo sources defined", count($sources)));
}

$available_actions = array('dir', 'photo', 'resize');
if (isset($_GET['action']) && in_array($_GET['action'], $available_actions)) {
    $action = $_GET['action'];
} else {
    $action = array_shift($available_actions);
}

if (isset($_GET['id'])) {
    $id = $_GET['id'];
} else {
    $id = 0;
}

switch ($action) {
    case 'resize':
        logIt("In Resize Mode");
        include_once('imgsize.php');
        break;
        
    case 'photo':
        logIt("In Photo Mode");
        include_once('photo.php');
        break;

    case 'dir':    
    default:
        logIt("In album mode");
        include_once('album.php');
}

